<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head th:include="inc/home::header"></head>
<link type="text/css" th:href="@{/css/content.css}" rel="stylesheet" />
<script type="text/javascript" >  

function validatePassword(){
	var patrn= /^.*(?=.{10,})(?=.*\d)(?=.*[A-Z])(?=.*[a-z]).*$/;
	var pwd = $("#password").val();
	if(!(patrn.test(pwd))){
		$.Zebra_Dialog('<div class="prompt"><div class="warning-icon"></div><div class="success-title">密码长度需大于10,并至少1个大写字母，1个小写字母，1个数字组成。!</div></div>', {
            'title':'提示',
            'buttons':['确定']
         });
		return false;
	}else{
		return true;
	}
}	

</script>
<body>
	<!--返回-->
	<div class="back"  onclick="loadPage('/index')">
		<img src="images/back.png" />
	</div>
	<div th:include="header :: header"></div>
	<div class="header-title">
		<span>修改密码</span>
	</div>
		<div class="spare-a">
			<div class="save-bg"><a  class="spare-tj"  onclick="passwordReset()">保 存</a></div>
			<div class="spare-add">
			 	<form id="passwordForm">
				<ul>
					<li>
						<div class="spare-addl">旧密码：</div>
						<div class="spare-addr"><input type="password" class="spare-add-input"  name="userPassword"   id="userPassword"/></div>
					</li>
					<li>
						<div class="spare-addl">新密码：</div>
						<div class="spare-addr">
						<input id="password" name="password" type="password"  class="spare-add-input"  onblur="validatePassword()"/>
						</div>
					</li>
					<li>
						<div class="spare-addl">确认新密码：</div>
						<div class="spare-addr"><input  id="confirmPassword"  type="password" class="spare-add-input"  name="confirmPassword"  /></div>
					</li>
					<li hidden="true">
						<div class="spare-addl">用户：</div>
						<div class="spare-addr"><input type="text" class="spare-add-input"  name="userName" th:value="${loginName}"   id="userName"  /></div>
					</li>
				</ul>
					</form>
			</div>
		</div>
	</body>
<script th:inline="javascript">  
/*<![CDATA[*/  

    function getDataJson(formId) {
    var dataJson = {};
    $("#"+formId).serializeArray().map(function (x) {
        if (dataJson[x.name] !== undefined) {
            if (!dataJson[x.name].push) {
                dataJson[x.name] = [dataJson[x.name]];
            }
            dataJson[x.name].push(x.value || '');
        } else {
            dataJson[x.name] = x.value || '';
        }
    });

    return dataJson;
}	

 function passwordReset() {

	 var result;
		var validate=getData();
		  if(!validate){
			 return false;
		 }
        var password = $("#password").val();
        var confirmPassword = $("#confirmPassword").val();
        
		if(!confirmPassword || confirmPassword.length < password.length){
			return;
		}
 
        if (password != confirmPassword){
			 top.$.Zebra_Dialog('<div class="prompt"><div class="warning-icon"></div><div class="success-title">两次密码不一致!</div></div>', {
		            'title':'提示',
		            'buttons':['确定']
		         });
            document.getElementById("confirmPassword").focus();
            return;
        }
		var obj=getDataJson("passwordForm");
		 $.ajax({
		     type: "post",
		     dataType: "json",
		     async:false,
		     url:"/unlogin/passwordReset" ,
		     data:obj,
		     success: function (data, status) {
		      	 if(data.userPassword==""){
		    		 top.$.Zebra_Dialog('<div class="prompt"><div class="success-icon"></div><div class="success-title">旧密码不对!</div></div>', {
				            'title':'提示',
				            'show_close_button':false,
				            'buttons':[    {caption: '确定', callback: function() { 
				             }}]
				         });
		    		 return;
		    	 }else{
		    		 top.$.Zebra_Dialog('<div class="prompt"><div class="success-icon"></div><div class="success-title">密码修改成功!</div></div>', {
				            'title':'提示',
				            'show_close_button':false,
				            'buttons':[    {caption: '确定', callback: function() { 
				            	window.location.href="/"
				             }}]
				         });
		    		 return;
		    	 }
		     },
		     error: function (data) {
		   
		     }
		 });
		 
 };
	  function verifyNull(obj){
			
			if(obj == null||obj.val()==""||obj.val()=="请选择"){
				top.$.Zebra_Dialog('<div class="prompt"><div class="warning-icon"></div><div class="success-title">输入的内容不能包含空</div></div>', {
					'title':'提示',
		 	         'buttons':['确定']
			     });
				return false;
			}
		return true;
	}      
	 function getData(){
		if(!verifyNull($("#userPassword"))){
	 		return false;
	 	}
		if(!verifyNull($("#password"))){
	 		return false;
	 	}
		if(!verifyNull($("#confirmPassword"))){
	 		return false;
	 	}
		return true;
	 }

/*]]>*/  
</script>	
</html>
